#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>

void test1()
{
    printf("--- test 1 ---\n");

    const char* x = "0x1111111111111111111111111111111111111111111111111";
    const char* y = "0x2222222222222";

    MPI a, b, c;
    a = mpi_scanval(x);
    b = mpi_scanval(y);
    c = mpi_new(0);

    mpi_add(c, a, b);
    mpi_print_helper(c);

    mpi_free(a);
    mpi_free(b);
    mpi_free(c);
}

void test2()
{
    printf("--- test 2 ---\n");
    long x = 0x111111111111;
    long y = 0x2222222;
    MPI  a, b, c;

    a = mpi_read_raw_data(&x, sizeof(x));
    b = mpi_read_raw_data(&y, sizeof(y));
    mpi_print_helper(a);
    mpi_print_helper(b);

    c = mpi_new(0);
    mpi_add(c, a, b);
    mpi_print_helper_v2(c);
    unsigned int nbyte;
    int sign;
    unsigned char* buf = mpi_get_buffer(c, &nbyte, &sign);
    for (size_t i = 0; i < nbyte; i++)
    {
        printf("%02x", buf[i]);
    }
    printf("\n");    
    free(buf);
    mpi_free(a);
    mpi_free(b);
    mpi_free(c);
}

int main(int argc, char const* argv[])
{
    test1();
    test2();
    return 0;
}
